package service

import (
	"context"
	"github.com/cloudwego/hertz/pkg/app"
	"github.com/jinzhu/copier"
	stage "stage/hertz_gen/stage"
	"stageRpc/client"
	stageRpcModel "stageRpc/kitex_gen/stage"
)

type GetFloorListService struct {
	RequestContext *app.RequestContext
	Context        context.Context
}

func NewGetFloorListService(Context context.Context, RequestContext *app.RequestContext) *GetFloorListService {
	return &GetFloorListService{RequestContext: RequestContext, Context: Context}
}

func (h *GetFloorListService) Run(req *stage.Param) (resp *[]*stage.Floor, err error) {
	var param = new(stageRpcModel.Param)
	if err = copier.Copy(param, req); err != nil {
		return nil, err
	}
	r, err := client.StageClient.GetFloorList(h.Context, param)
	if err != nil {
		return nil, err
	}
	tmpList := make([]*stage.Floor, 0)
	for _, v := range r {
		var tmp = new(stage.Floor)
		if err = copier.Copy(tmp, v); err != nil {
			return nil, err
		}
		tmpList = append(tmpList, tmp)
	}
	resp = &tmpList
	return
}
